import { useState } from "preact/hooks";
import type { Props } from "./index.ts";

// Brand marks shown inside the card. `fill="currentColor"` lets each icon
// inherit the color set on its container, so they pick up the accent palette.
const FrameworkIcon = ({ className }: { className?: string }) => (
  <svg
    width="22"
    height="22"
    viewBox="0 0 22 22"
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
    className={className}
  >
    <g clip-path="url(#clip0_3270_5141)">
      <path
        d="M1.39826 3.49915C3.16081 1.2435 8.76255 2.96245 14.0506 7.09387C19.3388 11.2255 22.362 16.2452 20.5994 18.5011C18.8919 20.6866 13.5812 19.1413 8.44318 15.2863L7.94708 14.9064C2.74167 10.8395 -0.268961 5.91245 1.31916 3.60755L1.39826 3.49915ZM6.12287 3.86145C5.05655 3.55105 4.16349 3.4496 3.48126 3.52258C2.80862 3.59456 2.41359 3.82447 2.18634 4.11536C1.95913 4.40623 1.83182 4.84493 1.92462 5.51477C2.01885 6.1944 2.33325 7.03667 2.8924 7.99622C4.00834 9.91122 5.98872 12.1076 8.56232 14.1183C11.136 16.1291 13.7467 17.5193 15.8748 18.1388C16.9408 18.4491 17.8333 18.5506 18.5154 18.4777C19.1881 18.4057 19.584 18.1759 19.8113 17.8849L19.8914 17.7687C20.0667 17.4807 20.1533 17.0715 20.0721 16.4855C19.9779 15.8059 19.6635 14.9636 19.1043 14.004C17.9883 12.0891 16.0079 9.89265 13.4344 7.88196C10.8609 5.87136 8.25091 4.48095 6.12287 3.86145Z"
        fill="currentColor"
      />
      <path
        d="M1.26735 18.3321C-0.455255 16.0458 2.65496 11.0798 8.01426 7.04125C13.3738 3.00263 19.0049 1.38157 20.7278 3.66798C22.3969 5.88302 19.5297 10.6128 14.4762 14.578L13.9808 14.9588C8.7053 18.9343 3.16692 20.5671 1.35158 18.4366L1.26735 18.3321ZM2.84013 13.8622C2.26432 14.8119 1.93519 15.6483 1.82911 16.3261C1.72454 16.9945 1.84438 17.4356 2.06654 17.7303C2.28869 18.0251 2.67949 18.2616 3.35053 18.3453C4.03139 18.4302 4.92633 18.3445 5.9979 18.0528C8.13647 17.4705 10.7706 16.1261 13.3788 14.1606C15.9873 12.195 18.0058 10.0331 19.155 8.13783C19.7306 7.18847 20.0596 6.35264 20.1657 5.67489C20.2703 5.00648 20.1508 4.56461 19.9286 4.26972L19.837 4.1623C19.6042 3.9185 19.2314 3.72892 18.6443 3.65567C17.9635 3.57079 17.0685 3.65648 15.997 3.94822C13.8584 4.53054 11.2243 5.875 8.616 7.84044C6.00784 9.8059 3.9893 11.967 2.84013 13.8622Z"
        fill="currentColor"
      />
      <path
        d="M10.9993 13.0302C12.1207 13.0302 13.0298 12.1211 13.0298 10.9997C13.0298 9.87835 12.1207 8.96924 10.9993 8.96924C9.87786 8.96924 8.96875 9.87835 8.96875 10.9997C8.96875 12.1211 9.87786 13.0302 10.9993 13.0302Z"
        fill="currentColor"
      />
    </g>
    <defs>
      <clipPath id="clip0_3270_5141">
        <rect width="22" height="22" fill="white" />
      </clipPath>
    </defs>
  </svg>
);

const TypeScriptIcon = ({ className }: { className?: string }) => (
  <svg
    width="22"
    height="22"
    viewBox="0 0 22 22"
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
    className={className}
  >
    <path
      d="M17.0352 2.50195C18.3965 2.50195 19.5 3.6055 19.5 4.9668V17.0371C19.4997 18.3982 18.3963 19.502 17.0352 19.502H4.96484C3.60371 19.502 2.50026 18.3982 2.5 17.0371V4.9668C2.5 3.6055 3.60355 2.50195 4.96484 2.50195H17.0352ZM4.96484 3.50195C4.15583 3.50195 3.5 4.15779 3.5 4.9668V17.0371C3.50026 17.8459 4.156 18.502 4.96484 18.502H17.0352C17.844 18.502 18.4997 17.8459 18.5 17.0371V4.9668C18.5 4.15779 17.8442 3.50195 17.0352 3.50195H4.96484Z"
      fill="currentColor"
    />
    <path
      fill-rule="evenodd"
      clip-rule="evenodd"
      d="M12.7853 15.4367V16.9034C13.0237 17.0256 13.3057 17.1172 13.6313 17.1783C13.9568 17.2395 14.2999 17.27 14.6606 17.27C15.0121 17.27 15.3461 17.2364 15.6624 17.1692C15.9788 17.102 16.2562 16.9912 16.4947 16.8369C16.7331 16.6826 16.9218 16.4809 17.0609 16.2319C17.2 15.9829 17.2695 15.6751 17.2695 15.3084C17.2695 15.0426 17.2298 14.8096 17.1503 14.6095C17.0708 14.4094 16.9562 14.2314 16.8064 14.0755C16.6567 13.9197 16.4771 13.7799 16.2677 13.6562C16.0583 13.5324 15.8222 13.4155 15.5593 13.3056C15.3667 13.2261 15.194 13.149 15.0412 13.0741C14.8883 12.9992 14.7584 12.9229 14.6514 12.845C14.5445 12.767 14.4619 12.6845 14.4039 12.5975C14.3458 12.5104 14.3167 12.4118 14.3167 12.3018C14.3167 12.201 14.3427 12.1101 14.3947 12.0291C14.4467 11.9482 14.52 11.8787 14.6148 11.8206C14.7095 11.7626 14.8257 11.7175 14.9632 11.6854C15.1008 11.6533 15.2536 11.6373 15.4217 11.6373C15.544 11.6373 15.6731 11.6465 15.8092 11.6648C15.9452 11.6831 16.082 11.7114 16.2196 11.7496C16.3571 11.7878 16.4908 11.8359 16.6208 11.8939C16.7507 11.952 16.8706 12.0192 16.9807 12.0956V10.7252C16.7575 10.6397 16.5138 10.5763 16.2494 10.535C15.985 10.4938 15.6816 10.4731 15.3392 10.4731C14.9907 10.4731 14.6606 10.5106 14.3488 10.5854C14.0371 10.6603 13.7627 10.7772 13.5258 10.936C13.2889 11.0949 13.1017 11.2974 12.9641 11.5433C12.8266 11.7893 12.7578 12.0834 12.7578 12.4256C12.7578 12.8625 12.8839 13.2353 13.1361 13.5439C13.3883 13.8525 13.7711 14.1137 14.2846 14.3276C14.4864 14.4101 14.6744 14.4911 14.8486 14.5705C15.0228 14.65 15.1734 14.7325 15.3002 14.818C15.4271 14.9036 15.5272 14.9968 15.6006 15.0976C15.6739 15.1984 15.7106 15.313 15.7106 15.4413C15.7106 15.5361 15.6877 15.6239 15.6418 15.7049C15.596 15.7858 15.5264 15.8561 15.4332 15.9157C15.34 15.9753 15.2238 16.0219 15.0847 16.0555C14.9456 16.0891 14.7829 16.1059 14.5964 16.1059C14.2785 16.1059 13.9637 16.0501 13.6519 15.9386C13.3401 15.8271 13.0512 15.6598 12.7853 15.4367ZM10.3197 11.8232H12.2012V10.6196H6.95703V11.8232H8.82928V17.1821H10.3197V11.8232Z"
      fill="currentColor"
    />
  </svg>
);
// Plain HTML/Preact starter block. Props are edited from the editor's Controls
// panel (see the schema in index.ts).
export function {{ block.clsName }}(props: Props) {
{% raw %}  const [count, setCount] = useState(props.initialCount);

  // Default to a neutral icon color; the color control can override it.
  const accent = props.accentColor || "#111827";

  // Map the "Button style" control (props.buttonVariant) to styles so the
  // selected variant is reflected in the preview.
  const variant = {
    solid: { background: accent, color: "#ffffff", border: `1px solid ${accent}` },
    outline: { background: "transparent", color: accent, border: `1px solid ${accent}` },
    ghost: { background: "transparent", color: accent, border: "1px solid transparent" },
  }[props.buttonVariant];

  return (
    <div
      style={{
        display: "flex",
        alignItems: "center",
        justifyContent: "space-between",
        gap: 32,
        padding: 24,
        border: "1px solid #e5e7eb",
        borderRadius: 12,
      }}
    >
      <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 8, color: accent }}>
          <FrameworkIcon />
          <TypeScriptIcon />
        </div>
        <div style={{ display: "flex", flexDirection: "column" }}>
          <span style={{ fontSize: 12, color: "#6b7280" }}>{props.subtitle}</span>
          <span style={{ fontSize: 16, color: "#111827" }}>{props.title}</span>
        </div>
      </div>
      <button
        type="button"
        onClick={() => setCount(count + 1)}
        style={{ padding: "8px 16px", borderRadius: 8, cursor: "pointer", ...variant }}
      >
        Count is {count}
      </button>
    </div>
  );
}
{% endraw %}
